package com.hbrj.controller;

import com.hbrj.entity.Student;
import com.hbrj.mapper.StudentMapper;
import com.hbrj.service.StudentService;
import org.hibernate.annotations.Source;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class StudentStart {
    @Resource
    StudentService studentService;

    @Resource
    StudentMapper studentMapper;

    @RequestMapping("/select")
    @ResponseBody
    public Student selectByName(HttpServletRequest request) {
        studentService.select(request.getParameter("name"));

        return studentService.select(request.getParameter("name"));
    }
    @RequestMapping("/update")
    @ResponseBody
    public String updateByGrade(HttpServletRequest request) {
        studentMapper.updateByGrade(request.getParameter("name"),request.getParameter("grade"));

        return "修改成功！";
    }
    @RequestMapping("/delete")
    @ResponseBody
    public String selectByDelete(HttpServletRequest request) {
        studentService.delete(Integer.parseInt(request.getParameter("id")));

        return "删除成功";
    }
    @RequestMapping("/add")
    @ResponseBody
    public String addStudent(HttpServletRequest request) {
        request.getParameter("id");
        request.getParameter("name");
        request.getParameter("Stu_id");
        request.getParameter("depart");
        request.getParameter("grade");
        request.getParameter("sex");
        Student student = new Student(request.getParameter("name"), request.getParameter("Stu_id"), request.getParameter("depart"), request.getParameter("grade"), request.getParameter("sex"));
        studentMapper.insertSelective(student);

        return "添加成功";
    }

}
